package cn.tedu.car.backend.base.response;

import lombok.Getter;
import lombok.Setter;

@Setter
@Getter
public class JsonResult {

    private Integer code;
    private String msg;
    private Object data;

    /**
     * 构造方法:针对于需要定义错误代码的方法
     */
    public JsonResult(StatusCode statusCode) {
        this.code = statusCode.getCode();
        this.msg = statusCode.getMsg();
    }

    /**
     * 构造方法:针对于需要定义错误代码和数据的方法
     */
    public JsonResult(StatusCode statusCode, Object data) {
        this.code = statusCode.getCode();
        this.msg = statusCode.getMsg();
        this.data = data;
    }

    public static JsonResult ok(Object data){
        return new JsonResult(StatusCode.SUCCESS, data);
    }

    public static JsonResult ok(){
        return ok(null);
    }
}